using System;
using Bussiness.Model.Type;
using NHibernate.Mapping.Attributes;

namespace Bussiness.Model
{
    [Class(Name = "Bussiness.Model.New, Bussiness")]
    public class New : BaseModel
    {
        private string _title;
        private string _description;
        private string _imageDesUrl;
        private string _contentHtml;
        private Category _category;
        private DateTime _createdDate;
        private DateTime _modifiedDate;
        private User _author;
        private Language _lang;

        #region Constructors.
        /// <summary>
        /// No-args constructor for tools.
        /// </summary>
        public New() { }

        /// <summary>
        /// Simple constructor.
        /// </summary>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="imageDesURL"></param>
        /// <param name="contentHTML"></param>
        /// <param name="category"></param>
        public New(string title, string description, string imageDesURL, string contentHTML, Category category)
        {
            _title = title;
            _description = description;
            _imageDesUrl = imageDesURL;
            _contentHtml = contentHTML;
            _category = category;
        }


        /// <summary>
        /// Full constructor.
        /// </summary>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="imageDesURL"></param>
        /// <param name="contentHTML"></param>
        /// <param name="category"></param>
        /// <param name="createdDate"></param>
        /// <param name="author"></param>
        public New(string title, string description, string imageDesURL, string contentHTML, Category category, DateTime createdDate, User author)
        {
            _title = title;
            _description = description;
            _imageDesUrl = imageDesURL;
            _contentHtml = contentHTML;
            _category = category;
            _createdDate = createdDate;
            _author = author;
        }
        #endregion

        [Property(NotNull = true, Length = 200)]
        public virtual string Title
        {
            get { return _title; }
            set { _title = value; }
        }

        [Property(NotNull = true, Length = 500)]
        public virtual string Description
        {
            get { return _description; }
            set { _description = value; }
        }

        [Property(Length = 150)]
        public virtual string ImageDesUrl
        {
            get { return _imageDesUrl; }
            set { _imageDesUrl = value; }
        }

        [Property(NotNull = true, Length = 4000)]
        public virtual string ContentHtml
        {
            get { return _contentHtml; }
            set { _contentHtml = value; }
        }

        [ManyToOne(0, OuterJoin = OuterJoinStrategy.False)]
        [Column(1, Name = "CATEGORY_ID", NotNull = false)]
        public virtual Category Category
        {
            get { return _category; }
            set { _category = value; }
        }

        [Property]
        public virtual DateTime CreatedDate
        {
            get { return _createdDate; }
            set { _createdDate = value; }
        }

        [Property]
        public virtual DateTime ModifiedDate
        {
            get { return _modifiedDate; }
            set { _modifiedDate = value; }
        }

        [ManyToOne(0, OuterJoin = OuterJoinStrategy.False)]
        [Column(1, Name = "USER_ID", NotNull = false)]
        public virtual User Author
        {
            get { return _author; }
            set { _author = value; }
        }

        [Property]
        public virtual Language Lang
        {
            set { _lang = value; }
            get { return _lang; }
        }

        #region Common methods.
        public override bool Equals(object obj)
        {
            if (obj == this) return true;
            if (!(obj is New)) return false;
            var that = (New)obj;
            if (this.Title != that.Title) return false;
            if (this.Description != that.Description) return false;
            if (this.ContentHtml != that.ContentHtml) return false;
            return this.Category != null ? this.Category == that.Category : that.Category == null;
        }

        public override int GetHashCode()
        {
            var result = this.Title.GetHashCode();
            result = 29 * result + this.Description.GetHashCode();
            result = 29 * result + this.ContentHtml.GetHashCode();
            if (this.ImageDesUrl != null) result = 29 * result + this.ImageDesUrl.GetHashCode();
            if (this.Category != null) result = 29 * result + this.GetHashCode();
            return result;
        }
        #endregion
    }
}
